import { SCRIPT_INSTALL_LEVEL_CONFIG } from './types'

export class ConfigProcessor {
  /**
   * 生成安装量级别样式
   */
  static generateInstallLevelStyles(): string {
    let styles = ''

    // 日安装量样式
    SCRIPT_INSTALL_LEVEL_CONFIG.daily.forEach((level) => {
      styles += `
        dd.daily-installs.${level.class.split(' ').join('.')}::after {
          content: '（${level.icon} ${level.description}）';
          color: ${level.color};
        }
      `
    })

    // 总安装量样式
    SCRIPT_INSTALL_LEVEL_CONFIG.total.forEach((level) => {
      styles += `
        dd.total-installs.${level.class.split(' ').join('.')}::after {
          content: '（${level.icon} ${level.description}）';
          color: ${level.color};
        }
      `
    })

    return styles
  }

  /**
   * 获取安装量级别信息
   */
  static getInstallLevel(type: 'daily' | 'total', value: number): {
    class: string
    icon: string
    color: string
  } | null {
    const levels = SCRIPT_INSTALL_LEVEL_CONFIG[type]
    for (let i = levels.length - 1; i >= 0; i--) {
      if (value >= levels[i].threshold) {
        return levels[i]
      }
    }
    return null
  }
}
